package com.pj.wisdomlogistics.ui.view;

import android.content.Context;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.pj.wisdomlogistics.R;
import com.zhy.autolayout.AutoRelativeLayout;
import com.zhy.autolayout.utils.AutoUtils;

/**
 * Created by WuFan on 2017/10/27.
 * 角标
 */

public class BadgerView extends AutoRelativeLayout{
    private TextView bar_num;
    private RelativeLayout.LayoutParams mParams1;
    private RelativeLayout.LayoutParams mParams2;

    public BadgerView(Context context) {
        super(context);
    }

    public BadgerView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        LayoutInflater.from(context).inflate(R.layout.view_badger , this);
        bar_num = (TextView)findViewById(R.id.tv_badger);
        mParams1 = new RelativeLayout.LayoutParams(AutoUtils.getPercentWidthSize(30), AutoUtils.getPercentHeightSize(30));
        mParams2 = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT , ViewGroup.LayoutParams.WRAP_CONTENT);
    }

    public BadgerView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    public void setMessageCount(int count) {
        if (count == 0) {
            bar_num.setVisibility(View.GONE);
        } else {
            bar_num.setVisibility(View.VISIBLE);
            if (count < 100) {
                bar_num.setLayoutParams(mParams1);
                bar_num.setText(count + "");
            } else {
                bar_num.setLayoutParams(mParams2);
                bar_num.setText("99+");
            }
        }
        invalidate();
    }


}
